//
//  JYBaseTableViewCell.m
//  JYTableBaseAdaptorTest
//
//  Created by 应明顺 on 11/28/18.
//  Copyright © 2018 JackYing. All rights reserved.
//

#import "JYBaseTableViewCell.h"

@implementation JYBaseTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.titleLab = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLab];
    
    self.contentV = [[UILabel alloc] init];
    [self.contentView addSubview:self.contentV];
}

// 在该处，cell的大小还未确定
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.titleLab = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLab];
        
        self.contentV = [[UILabel alloc] init];
        [self.contentView addSubview:self.contentV];
        
        // 不在layoutSubviews中使用frame进行定位，否则自动布局约束可能不生效
        CGFloat contentViewW = self.frame.size.width;
        CGFloat contentViewH = self.frame.size.height;
        self.titleLab.frame = CGRectMake(20, 0, contentViewW/3, contentViewH-2);
        self.contentV.frame = CGRectMake(CGRectGetMaxX(self.titleLab.frame), 0,
                                         contentViewW - CGRectGetMaxX(self.titleLab.frame) - 20, contentViewH-2);
    }
    return self;
}

- (void)setModel:(JYBaseCellModel *)model {
    if (_model != model) {
        _model = model;
    }
    
    self.titleLab.text = _model.title;
    if ([self.contentV respondsToSelector:@selector(setText:)]) {
         ((UILabel *)self.contentV).text = _model.content;
    }
}

- (void)setContentV:(UIView *)contentV {
    if (_contentV != contentV) {
        _contentV = contentV;
    }
    [self.contentView addSubview:_contentV];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



@end
